package com.huanletao.proxy.jdkproxy;

import java.lang.reflect.Proxy;

/**
 * <p>
 *
 * </p>
 *
 * @package: com.huanletao.proxy.jdkproxy
 * @Description:
 * @className: Main
 * @author: @NNCSKJ ADMIN
 * @copyright: Copyright (c) 2022/6/26 12:14
 * @version: V1.0
 */
public class Main {
    public static void main(String[] args) {


        LoginService loginService = new DefaultLoginServiceImpl();

//        String admin = loginService.login("admin", "123");
//        System.out.println("admin = " + admin);
        //需求变化; 不改变原来的代码, 判断是否允许访问登录方法;

        PermissionInterceptor interceptor = new PermissionInterceptor(loginService);

        LoginService proxyInstance = (LoginService) Proxy.newProxyInstance(Main.class.getClassLoader(),
                new Class[]{LoginService.class}, interceptor);

        String zhangsan = proxyInstance.login("admin1", "123");
        String admin = proxyInstance.logout("admin");


    }
}
